//
//  ForumViewController.m
//  AutoHome
//
//  Created by Flying meat on 9/11/15.
//  Copyright (c) 2015 CaoFeng. All rights reserved.
//

#import "ForumViewController.h"
#import "CustomCell.h"
#import "SecondCustomCell.h"
#import "ThirdCustomCell.h"
#import "MJRefresh.h"
#import "HTTPRequestManager.h"
#import "AFNetworking.h"
#import "UIImageView+AFNetworking.h"
#import "ForumModel.h"
#import "DetailViewController.h"
#import "FrumDetailViewController.h"
#import "JinXViewController.h"
@interface ForumViewController ()<UIScrollViewDelegate,UITableViewDataSource,UITableViewDelegate,MJRefreshBaseViewDelegate>

{
    NSMutableArray *_dataArray;
    NSArray*_titleArray;
    MJRefreshFooterView *_foot;
    MJRefreshHeaderView *_head;
       BOOL _isDragDown;
       int _currentPage;
       UILabel *_label;
       CGFloat _p;//没网状态下改变label的alpha
    int _cellcount;
    int _tablecount;
    
    NSString *_newid;
    
    
    NSArray *_CheXiTitleArray;
    
    NSArray *_CarNameArray;
    NSArray *_CityName;
    NSArray *_CityTitleCharArray;
    NSArray *_ThemeArray;
    
    NSMutableArray *_newIDArray;
    
    
    NSArray *_ABTarray;
    
}
@property (weak, nonatomic) IBOutlet UIView *topView;
@property (weak, nonatomic) IBOutlet UIButton *newsPaperButton;
@property (weak, nonatomic) IBOutlet UIButton *usualForum;
@property (weak, nonatomic) IBOutlet UIScrollView *smallScrollView;
@property (weak, nonatomic) IBOutlet UIImageView *imgWithScroll;
@property (weak, nonatomic) IBOutlet UIScrollView *BigScrollView;
@property (weak, nonatomic) IBOutlet UITableView *firstTableView;
@property (weak, nonatomic) IBOutlet UILabel *UnderLabel;
@property (nonatomic,strong)UITableView *secondTable;
@property (nonatomic,strong)UITableView *thridTabel;
@property (nonatomic,strong)UIView *pushView;
@property (nonatomic,strong)UIView *pushViewTitleView;

@property (nonatomic,strong)UIView *pushViewDetail;



@property (nonatomic,strong)UILabel *pushTitleLabel;
@property (nonatomic,strong)UIButton *pushTitleButton;
@property (nonatomic,strong)UIView *BiggestView;
@property (nonatomic,strong)UILabel *pushgrayLabel;
@property (nonatomic,strong)UIButton *backButton;








@end

@implementation ForumViewController
- (instancetype)initWithCoder:(NSCoder *)coder
{
    self = [super initWithCoder:coder];
    if (self) {
        
        _tablecount=0;
        _currentPage=0;
        
        _p=1;
        
        
        
        _ABTarray=[[NSArray alloc]init];
        _newIDArray=[[NSMutableArray alloc]init];
        _CheXiTitleArray=[[NSArray alloc]init];
        _CarNameArray=[[NSArray alloc]init];
        _CityName=[[NSArray alloc]init];
        
        _titleArray=[[NSArray alloc]init];
        _dataArray=[[NSMutableArray alloc]init];
       
        _CityTitleCharArray=[[NSArray alloc]init];
        
        _ThemeArray=[[NSArray alloc]init];
        
        _titleArray=@[@"全部",@"汽车之家十年",@"媳妇当车模",@"美人''记''",@"论坛评人堂",@"论坛讲师",@"精挑细选",@"现身说法",@"高端阵地",@"电动车",@"汇买车",@"行车点评",@"超级试驾员",@"海外购车",@"经典老车",@"妹子选车",@"优惠购车",@"原创大片",@"顶配风采",@"改装有理",@"养车有道",@"首发阵营",@"新车直播",@"历史选题",@"精彩视频",@"摩友天地",@"蜜月之旅",@"甜蜜婚礼",@"摄影课堂",@"车有聚会",@"单车部落",@"杂谈俱乐部",@"华北游记",@"西南游记",@"东北游记",@"西北游记",@"华中游记",@"华南游记",@"华东游记",@"港澳台游记",@"海外游记",@"沧海遗珠"];
        
        
    _CheXiTitleArray=@[@"A",@"B",@"C",@"D",@"E",@"F",@"G",@"H",@"J",@"K",@"L",@"M",@"N",@"O",@"P",@"Q",@"R",@"S",@"T",@"V",@"W",@"X",@"Y",@"Z"];
        
        _CarNameArray=@[@[@"ABT",@"阿尔法罗密欧",@"阿斯顿马丁",@"安凯客车",@"奥迪"],
                        @[@"BAC",@"巴博斯",@"宝骏",@"宝马",@"宝沃",@"保时捷",@"北京",@"北汽幻速",@"北汽威旺",@"北汽新能源",@"北汽制造",@"奔驰",@"奔腾",@"本田",@"比亚迪",@"别克",@"宾利",@"布加迪"],
                        @[@"昌河",@"成功汽车",@"长安",@"长安商用",@"长城"],
                        @[@"大迪",@"大发",@"大众",@"道奇",@"东风",@"东风风度",@"东风风神",@"东风风行",@"东风小康",@"东南",@"Datsun",@"DS"],
                        @[@"Elemental"],
                        @[@"法拉利",@"菲亚特",@"弗纳萨利",@"福迪",@"福汽启腾",@"福特",@"福田",@"FISKER",@"丰田"],
                        @[@"观致",@"光冈",@"广汽传祺",@"广汽吉奥",@"GMC",@"Gumpert"],
                        @[@"哈飞",@"哈弗",@"海格",@"海马",@"悍马",@"恒天",@"红旗",@"华凯",@"华利",@"华普",@"华骐",@"华颂",@"华泰",@"黄海",@"霍顿"],
                        @[@"Jeep",@"吉利汽车",@"佳跃",@"江淮",@"江铃",@"江铃集团轻汽",@"捷豹",@"金杯",@"金龙",@"金旅",@"九龙"],
                        @[@"卡尔森",@"卡威",@"开利",@"开瑞",@"凯佰赫",@"凯迪拉克",@"凯翼",@"康迪",@"科尼塞克",@"克莱斯勒",@"KTM"],
                        @[@"拉达",@"兰博基尼",@"蓝旗亚",@"朗世",@"劳伦士",@"劳斯莱斯",@"雷丁",@"雷克萨斯",@"雷诺",@"理念",@"力帆",@"莲花汽车",@"猎豹汽车",@"林肯",@"铃木",@"陆地方舟",@"陆风",@"路虎",@"路特斯",@"LOCAL MOTORS"],
                        @[@"马自达",@"玛莎拉蒂",@"迈巴赫",@"迈凯伦",@"摩根",@"MG",@"MiNi"],
                        @[@"NOBLE",@"纳智捷",@"南京京龙"],
                        @[@"讴歌",@"欧宝",@"欧朗",@"欧联"],
                        @[@"帕加尼",@"佩奇奥"],
                        @[@"奇瑞",@"启辰",@"起亚",@"前途",@"乔治巴顿"],
                        @[@"日产",@"荣威",@"如虎",@"瑞麒"],
                        @[@"萨博",@"赛麟",@"三菱",@"陕汽通家",@"上汽大众",@"世爵",@"双环",@"双龙",@"思铭",@"斯巴鲁",@"斯达泰克",@"斯柯达",@"Scion",@"smart",@"SPIRRA",@"SSC"],
                        @[@"TVR",@"塔塔",@"泰卡特",@"特斯拉",@"腾势"],
                        @[@"Venturi"],
                        @[@"W Motors",@"威麟",@"威兹曼",@"潍柴英致",@"沃尔沃",@"五菱汽车",@"五十铃"],
                        @[@"西雅特",@"现代",@"新凯",@"雪佛兰",@"雪铁龙"],
                        @[@"亚琛施纳泽",@"一汽",@"依维柯",@"英菲尼迪",@"永源",@"游侠",@"御捷"],
                        @[@"之诺",@"知豆",@"中华",@"中兴",@"众泰"]];
        
        
        
        
        
        _ABTarray=@[@"ABT S1论坛",@"ABT A3论坛",@"ABT A4论坛",@"ABT A5论坛",@"ABT RS4论坛",@"ABT A8L论坛",@"ABT Q5论坛",@"ABT TT 论坛"];
        
        
        
        
        _CityTitleCharArray=@[@"A",@"B",@"C",@"F",@"G",@"H",@"J",@"L",@"N",@"Q",@"S",@"T",@"X",@"Y",@"Z"];
        
        _CityName=@[@[@"安徽",@"澳门"],@[@"北京"],@[@"重庆"],@[@"福建"],@[@"甘肃",@"广东",@"广西",@"贵州"],@[@"海南",@"河北",@"黑龙江",@"河南",@"湖北",@"湖南",@"海外"],@[@"江苏",@"江西",@"吉林"],@[@"辽宁"],@[@"内蒙古",@"宁夏"],@[@"青海"],@[@"山西",@"山东",@"上海",@"四川",@"陕西"],@[@"天津",@"台湾"],@[@"西藏",@"新疆",@"香港"],@[@"云南"],@[@"浙江"]];
       
        _ThemeArray=@[@"精彩作业论坛",@"维修保养论坛",@"装饰改装论坛",@"自驾游论坛",@"摄影论坛",@"车展快报论坛",@"社区公告论坛",@"服务商论坛",@"经销商论坛",@"自行车论坛",@"GPS论坛",@"App应用体验论坛",@"摩托车论坛",@"卡丁车论坛",@"精彩连载论坛",@"活动报道论坛",@"二手车论坛",@"FIST Auto论坛",@"亿佰欧论坛",@"金驰之星论坛",@"autobots论坛",@"运通德系改装论坛",@"车168论坛",@"儿童安全座椅论坛",@"ACE REPUBLIC论坛",@"Manthry Motors论坛",@"鬼马改装论坛",@"VTC上海汇论坛",@"TCPracing论坛",@"名欧改装论坛",@"BBA Motorsport论坛",@"杭州车世界论坛",@"KUBE8论坛",@"上海奥士博改装论坛",@"SPT-China论坛",@"SXXVM汽车养护中心论坛",@"AUTOFANS车迷店论坛",@"DRS AUTO论坛",@"BAC-彼斯博克论坛",@"名雅保时捷论坛",@"机油论坛",@"轮胎论坛",@"美食论坛",@"模型论坛",@"足球论坛",@"飞机/舰船/战车论坛/无线电论坛",@"篮球论坛",@"育儿论坛",@"数码论坛",@"台球论坛",@"户外/极限运动论坛",@"家装论坛",@"宠物论坛",@"理财论坛",@"钓鱼论坛",@"成都HRS高转速联盟论坛",@"绍兴transformod论坛",@"Noise-Performance论坛",@"汽车之家电台论坛",@"房车论坛",@"超级试驾员论坛",@"吵完还是朋友论坛"];
        
        
        
        
        
        
        
        
        
        
        
        
    }
    return self;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    [self setbuttonAndView];
    [self addObserveNetStatus];
    [self mj];
    
}

-(void)mj
{
    _foot = [[MJRefreshFooterView alloc]init];
    _foot.scrollView =self.firstTableView ;
    _foot.delegate =self;
    
    _head = [[MJRefreshHeaderView alloc]init];
    _head.scrollView =self.firstTableView;
    _head.delegate =self;
    
}
-(void)dealloc
{
    
    [_foot free];
    
}
-(void)addObserveNetStatus
{
    
    //检测网络状态
    [[AFNetworkReachabilityManager sharedManager]startMonitoring];
    //状态发生改变
    [[AFNetworkReachabilityManager sharedManager]setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
        if (status==AFNetworkReachabilityStatusNotReachable) {
            _label=[[UILabel alloc]initWithFrame:CGRectMake(0,self.view.frame.size.height-100, self.view.frame.size.width, 60)];
            _label.text=@"当前网络不可用,请检查网络设置";
            _label.backgroundColor=[UIColor redColor];
            _label.textColor=[UIColor whiteColor];
            _label.textAlignment=NSTextAlignmentCenter;
            
            
            [self.view addSubview:_label];
            
            [NSTimer scheduledTimerWithTimeInterval:0.05 target:self selector:@selector(label) userInfo:nil repeats:YES];
        }else
        {
            [self getInforFromNet];
            
        }
        
        
    }];
    
    
}
-(void)label
{
    
    
    if (_p<0) {
        return;
    }
    
    _label.alpha=_p;
    _p=_p-0.01;
    
    
}

#pragma mark-=========从网络获取数据
-(void)getInforFromNet
{
    
    [[HTTPRequestManager shareInstance]getFancyTopicInforByc:_currentPage success:^(id responseObject) {
        
        
        
        [_dataArray removeAllObjects];
        for (NSDictionary *dic in responseObject) {

            
        //用模型来接各个内容;
            ForumModel *model=[[ForumModel alloc]init];
            model.imgurl=dic[@"smallpic"];
            model.titleLabel=dic[@"title"];
            model.typeLabel=dic[@"bbsname"];
            model.answer=[NSString stringWithFormat:@"%@",dic[@"replycounts"]];
            model.topicid=[NSString stringWithFormat:@"%@",dic[@"topicid"]];
            [_dataArray addObject:model];
            
          
            
        }
        [self.firstTableView reloadData];
        
        [_foot endRefreshing];
        [_head endRefreshing];
        
    } failure:^(NSError *error) {
        
        
        
        NSLog(@"获取精选日报数据失败,error==%@",error);
        
        
    }];
    
    
    
    
    
    
    
    
}







#pragma mark=========设置控件的内容
-(void)setbuttonAndView
{
    
    

    //设置浮在界面最上面的空view
    self.BiggestView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 568)];
    self.BiggestView.backgroundColor=[UIColor clearColor];
    self.BiggestView.hidden=YES;
    [self.view addSubview:self.BiggestView];
    
    
    
    //设置推出界面 1
    
    self.pushView=[[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width, 0, self.firstTableView.frame.size.width, self.view.frame.size.height+44)];
    
    self.pushView.backgroundColor=[UIColor clearColor];
    [self.view addSubview:self.pushView];

    
     //推出界面 2
    self.pushViewDetail=[[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width*2, 0, self.firstTableView.frame.size.width, self.view.frame.size.height+44)];
    self.pushViewDetail.backgroundColor=[UIColor grayColor];
    [self.view addSubview:self.pushViewDetail];
    
    
    
    
    
    //设置推出界面的titlteView
    self.pushViewTitleView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width,64)];
    
    self.pushViewTitleView.backgroundColor=[UIColor colorWithRed:179 green:179 blue:186 alpha:1];
    [self.pushView addSubview:self.pushViewTitleView];
    
    
    
    
    //设置二级抽屉的返回button
    
    self.backButton=[UIButton buttonWithType:UIButtonTypeCustom];
    self.backButton.frame=CGRectMake(-15, 20, 80, 44);
    self.backButton.titleLabel.text=@"返回";
    self.backButton.titleLabel.textColor=[UIColor blueColor];
    NSMutableAttributedString *backstr=[[NSMutableAttributedString alloc]initWithString:self.backButton.titleLabel.text];
    NSRange backRange={0,[backstr length]};
    [backstr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleThick] range:backRange];
    [self.backButton addTarget:self action:@selector(backToOne) forControlEvents:UIControlEventTouchUpInside];
    [self.backButton setAttributedTitle:backstr forState:UIControlStateNormal];
    
    
    
    self.backButton.hidden=YES;
    [self.pushViewTitleView addSubview:self.backButton];
    

    
    
    
    //设置一条灰色的分栏
    self.pushgrayLabel=[[UILabel alloc]initWithFrame:CGRectMake(0, 63, self.view.frame.size.width, 1)];
    self.pushgrayLabel.backgroundColor=[UIColor darkGrayColor];
    [self.pushViewTitleView addSubview:self.pushgrayLabel];
    
    
    
    
    
    //设置推出界面的titlelabel
    self.pushTitleLabel=[[UILabel alloc]initWithFrame:CGRectMake(70, 20, 80, 44)];
    self.pushTitleLabel.text=@"精选分类";
    self.pushTitleLabel.textColor=[UIColor darkGrayColor];
    self.pushTitleLabel.textAlignment=NSTextAlignmentCenter;
    [self.pushViewTitleView addSubview:self.pushTitleLabel];
    
    
    
    
    
    
    //设置推出界面的button
    self.pushTitleButton=[[UIButton alloc]initWithFrame:CGRectMake(self.view.frame.size.width-120, 20,60, 44)];
    self.pushTitleButton.titleLabel.text=@"关闭";
    self.pushTitleButton.titleLabel.textColor=[UIColor blueColor];
    
    NSMutableAttributedString *pushstr=[[NSMutableAttributedString alloc]initWithString:self.pushTitleButton.titleLabel.text];
    
    NSRange pushstrRange={0,[pushstr length]};
    [pushstr addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleThick] range:pushstrRange];
    [self.pushTitleButton setAttributedTitle:pushstr forState:UIControlStateNormal];
    [self.pushTitleButton addTarget:self action:@selector(closePushView) forControlEvents:UIControlEventTouchUpInside];
    
    [self.pushViewTitleView addSubview:self.pushTitleButton];
    
    
    
    
    
    
    
    //设置第三个tableview也就是推出界面的tableview;
    self.thridTabel=[[UITableView alloc]initWithFrame:CGRectMake(0, 64, self.firstTableView.frame.size.width-60, self.firstTableView.frame.size.height+40) ];
    
    self.thridTabel.tag=2003;
    self.thridTabel.delegate=self;
    self.thridTabel.dataSource=self;
    self.thridTabel.showsVerticalScrollIndicator=NO;
    
    
     [self.thridTabel registerNib:[UINib nibWithNibName:@"ThirdCustomCell" bundle:nil] forCellReuseIdentifier:@"ThirdCustomCell"];
    [self.pushView addSubview:self.thridTabel];
    
    
    

    self.secondTable=[[UITableView alloc]initWithFrame:CGRectMake(self.firstTableView.frame.size.width, 0, 320, 300)];
    
    [self.secondTable registerNib:[UINib nibWithNibName:@"SecondCustomCell" bundle:nil] forCellReuseIdentifier:@"SecondCustomCell"];
    self.secondTable.delegate=self;
    self.secondTable.dataSource=self;
    self.secondTable.tag=2002;
    self.secondTable.backgroundColor=[UIColor clearColor];
    self.secondTable.showsVerticalScrollIndicator=NO;
    
    [self.BigScrollView addSubview:self.secondTable];
    
    
    
    
    self.firstTableView.tag=2001;
    
    [self.firstTableView registerNib:[UINib nibWithNibName:@"CustomCell" bundle:nil] forCellReuseIdentifier:@"CustomCell"];
     [self.firstTableView reloadData];
    
    
    self.BigScrollView.tag=1002;
    self.BigScrollView.delegate=self;
    self.BigScrollView.contentSize=CGSizeMake(self.firstTableView.frame.size.width*2, 0);
    self.BigScrollView.showsHorizontalScrollIndicator=NO;
    
    self.smallScrollView.tag=1001;
    self.smallScrollView.contentSize=CGSizeMake(_titleArray.count*90, 0);
    self.smallScrollView.showsHorizontalScrollIndicator=NO;
    
   
    
    
    
    
    NSMutableAttributedString *str=[[NSMutableAttributedString alloc]initWithString:self.newsPaperButton.titleLabel.text];
    NSRange strRange={0,[str length]};
    [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleThick] range:strRange];
    [self.newsPaperButton setAttributedTitle:str forState:UIControlStateNormal];
    [self.newsPaperButton addTarget:self action:@selector(topclick:) forControlEvents:UIControlEventTouchUpInside];
    self.newsPaperButton.selected=YES;
    self.newsPaperButton.titleLabel.textColor=[UIColor blueColor];
    self.newsPaperButton.tag=301;
    
   
    
    NSMutableAttributedString *str2=[[NSMutableAttributedString alloc]initWithString:self.usualForum.titleLabel.text];
    
    NSRange strRange2={0,[str length]};
    [str2 addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleThick] range:strRange2];
    [self.usualForum setAttributedTitle:str2 forState:UIControlStateNormal];
    [self.usualForum addTarget:self action:@selector(topclick:) forControlEvents:UIControlEventTouchUpInside];
    
    self.usualForum.titleLabel.textColor=[UIColor darkGrayColor];
    self.usualForum.tag=302;
    
    
    
    
    
    
    
    
    
    for (int i=0; i<_titleArray.count; i++) {
        
        
        
        
        //下划线Button
        
        NSMutableAttributedString *str=[[NSMutableAttributedString alloc]initWithString:_titleArray[i]];
        
        NSRange strRange={0,[str length]};
        [str addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleThick] range:strRange];
        
        
        
        
        
        UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
        button.titleLabel.font=[UIFont systemFontOfSize:15];
        button.titleLabel.textColor=[UIColor darkGrayColor];
        
        button.frame=CGRectMake(i*90, 0, 90, 40);
        [button setAttributedTitle:str forState:UIControlStateNormal];
        
        //给button打上tag值
        button.tag=100+i;
        
        [button addTarget:self action:@selector(click:) forControlEvents:UIControlEventTouchUpInside];
        [self.smallScrollView addSubview:button];
        
        
        

        
        if (i==0) {
            button.selected=YES;
            button.titleLabel.textColor=[UIColor blueColor];

        }
        
    }
    
    
    
    
    
    
    
}



-(void)backToOne
{
    
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationBeginsFromCurrentState:1.0];
    
    self.pushViewDetail.frame=CGRectMake(self.view.frame.size.width*2, 0, self.firstTableView.frame.size.width, self.firstTableView.frame.size.height);

    _tablecount=1;
    
    [self.thridTabel reloadData];
    self.thridTabel.userInteractionEnabled=YES;
    [self.pushView addSubview:self.pushViewTitleView];
    [self.pushView addSubview:self.thridTabel];
    
    self.backButton.hidden=YES;
    
    [UIView commitAnimations];
    
    
    
    
}
#pragma mark-=============推出界面关闭按钮,关闭推出界面
-(void)closePushView
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationBeginsFromCurrentState:1.0];
    
    self.pushView.frame=CGRectMake(self.view.frame.size.width*2, 0, self.firstTableView.frame.size.width, self.firstTableView.frame.size.height);
    
    self.pushViewDetail.frame=CGRectMake(self.view.frame.size.width*2, 0, self.firstTableView.frame.size.width, self.firstTableView.frame.size.height);
    self.BiggestView.hidden=YES;

    
    self.firstTableView.userInteractionEnabled=YES;
    
    [self.pushView addSubview:self.pushViewTitleView];
    [self.pushView addSubview:self.thridTabel];
    self.backButton.hidden=YES;
    
    [UIView commitAnimations];
    
    
}


-(void)topclick:(UIButton *)button
{

    for (UIButton *button in self.topView.subviews) {
        //如果是按钮则取反状态
        if ([button isKindOfClass:[UIButton class]]) {
            
            button.selected=NO;
            button.titleLabel.textColor=[UIColor darkGrayColor];
            
            
            
        }
    }
    button.selected=YES;
    button.titleLabel.textColor=[UIColor blueColor];
    button.backgroundColor=[UIColor clearColor];

    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationBeginsFromCurrentState:5.0];
    
    self.UnderLabel.frame=CGRectMake(button.frame.origin.x+10, 40,button.frame.size.width-20, 4);
    
    
    
    if ([button.titleLabel.text isEqualToString:@"精选日报"]) {
        self.BigScrollView.contentOffset=CGPointMake(0, 0);
        
    }else {
        
        self.BigScrollView.contentOffset=CGPointMake(self.firstTableView.frame.size.width, 0);
        [self scrollViewDidEndDecelerating:self.BigScrollView];
        
    }

     [UIView commitAnimations];
}





#pragma   mark ------------====点击标题触发事件
//点击顶部标题所触发的事件
-(void)click:(UIButton *)button
{
    for (UIButton *button in self.smallScrollView.subviews) {
        //如果是按钮则取反状态
        if ([button isKindOfClass:[UIButton class]]) {
            
            button.selected=NO;
            button.titleLabel.textColor=[UIColor darkGrayColor];
            UITableViewCell *cell=(UITableViewCell *)[self.thridTabel viewWithTag:button.tag+600];
            cell.accessoryType=UITableViewCellAccessoryNone;
         
            
        }
    }
    button.selected=YES;
    button.titleLabel.textColor=[UIColor blueColor];
    button.backgroundColor=[UIColor clearColor];
     UITableViewCell *cell=(UITableViewCell *)[self.thridTabel viewWithTag:button.tag+600];
      _cellcount=(int)button.tag-100;
     cell.accessoryType=UITableViewCellAccessoryCheckmark;
    
    [self.thridTabel reloadData];
    
    switch (button.tag) {
        case 100:
            _currentPage=0;
            [self getInforFromNet];
            
            break;
        
        case 101:
            _currentPage=233;
            [self getInforFromNet];
            break;
        case 102:
            _currentPage=104;
            [self getInforFromNet];
            break;
        case 103:
            _currentPage=110;
            [self getInforFromNet];
            break;
        case 104:
            _currentPage=172;
            [self getInforFromNet];
            break;
        case 105:
            _currentPage=230;
            [self getInforFromNet];
            break;
        case 106:
            _currentPage=121;
            [self getInforFromNet];
            break;
        case 107:
            _currentPage=106;
            [self getInforFromNet];
            break;
        case 108:
            _currentPage=118;
            [self getInforFromNet];
            break;
        case 109:
            _currentPage=210;
            [self getInforFromNet];
            break;
        case 110:
            _currentPage=199;
            [self getInforFromNet];
            break;
        case 111:
            _currentPage=198;
            [self getInforFromNet];
            break;
        case 112:
            _currentPage=168;
            [self getInforFromNet];
            break;
        case 113:
            _currentPage=113;
            [self getInforFromNet];
            break;
        case 114:
            _currentPage=109;
            [self getInforFromNet];
            break;
        case 115:
            _currentPage=191;
            [self getInforFromNet];
            break;
        case 116:
            _currentPage=196;
            [self getInforFromNet];
            break;
        case 117:
            _currentPage=107;
            [self getInforFromNet];
            break;
        case 118:
            _currentPage=105;
            [self getInforFromNet];
            break;
        case 119:
            _currentPage=122;
            [self getInforFromNet];
            break;
        case 120:
            _currentPage=194;
            [self getInforFromNet];
            break;
        case 121:
            _currentPage=119;
            [self getInforFromNet];
            break;
        case 122:
            _currentPage=112;
            [self getInforFromNet];
            break;
        case 123:
            _currentPage=120;
            [self getInforFromNet];
            break;
        case 124:
            _currentPage=227;
            [self getInforFromNet];
            break;
        case 125:
            _currentPage=184;
            [self getInforFromNet];
            break;
        case 126:
            _currentPage=108;
            [self getInforFromNet];
            break;
        case 127:
            _currentPage=124;
            [self getInforFromNet];
            break;
        case 128:
            _currentPage=123;
            [self getInforFromNet];
            break;
        case 129:
            _currentPage=185;
            [self getInforFromNet];
            break;
        case 130:
            _currentPage=186;
            [self getInforFromNet];
            break;
        case 131:
            _currentPage=214;
            [self getInforFromNet];
            break;
        case 132:
            _currentPage=218;
            [self getInforFromNet];
            break;
        case 133:
            _currentPage=223;
            [self getInforFromNet];
            break;
        case 134:
            _currentPage=221;
            [self getInforFromNet];
            break;
        case 135:
            _currentPage=222;
            [self getInforFromNet];
            break;
        case 136:
            _currentPage=220;
            [self getInforFromNet];
            break;
        case 137:
            _currentPage=224;
            [self getInforFromNet];
            break;
        case 138:
            _currentPage=219;
            [self getInforFromNet];
            break;
        case 139:
            _currentPage=225;
            [self getInforFromNet];
            break;
        case 140:
            _currentPage=226;
            [self getInforFromNet];
            break;
        case 141:
            _currentPage=212;
            [self getInforFromNet];
            break;
       
        default:
            break;
    }
}


#pragma MJrefresh 刷新

- (void)refreshViewBeginRefreshing:(MJRefreshBaseView *)refreshView
{
    if (refreshView == _head) {
        _isDragDown = YES;
        
    }else
    {
        _isDragDown = NO;
        
    }
    //重新请求数据
    
    
    [self getInforFromNet];
    
}



#pragma mark========UIScrollViewDelegate
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    if (scrollView.tag==1002) {

    
        
        if (scrollView.contentOffset.x==self.firstTableView.frame.size.width) {
            
            self.usualForum.selected=YES;
            self.usualForum.titleLabel.textColor=[UIColor blueColor];
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationBeginsFromCurrentState:5.0];
            
            self.UnderLabel.frame=CGRectMake(self.usualForum.frame.origin.x+10, 40,self.usualForum.frame.size.width-20, 4);
            
            
            self.newsPaperButton.titleLabel.textColor=[UIColor darkGrayColor];
            
            [UIView commitAnimations];
        }else
        {
            
            self.newsPaperButton.selected=YES;
            self.newsPaperButton.titleLabel.textColor=[UIColor blueColor];
            [UIView beginAnimations:nil context:nil];
            [UIView setAnimationBeginsFromCurrentState:5.0];
            
            self.UnderLabel.frame=CGRectMake(self.newsPaperButton.frame.origin.x+10, 40,self.newsPaperButton.frame.size.width-20, 4);
            
            
            self.usualForum.titleLabel.textColor=[UIColor darkGrayColor];
            
            [UIView commitAnimations];
        }
        
        
        
        
    }
    
    
}



#pragma mark===============车系论坛推出的页面
-(void)pushToCheXiForum
{
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationBeginsFromCurrentState:2];
    self.pushView.frame=CGRectMake(60, 0, self.view.frame.size.width, 568);
    
    
    self.pushTitleLabel.text=@"车系论坛";
    
    
    
    _tablecount=1;
    
    [self.thridTabel reloadData];
    self.BiggestView.hidden=NO;
    self.BiggestView.backgroundColor=[UIColor grayColor];
    self.BiggestView.alpha=0.8;
    [self.view bringSubviewToFront:self.pushView];
    self.firstTableView.userInteractionEnabled=NO;
    self.tabBarController.tabBar.hidden=YES;
    
    
    [UIView commitAnimations];

    
    
}



#pragma mark================车子论坛各项推出有一个抽屉

-(void)pushToCheXiEveryOne
{
    
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationBeginsFromCurrentState:2];
  
    self.pushViewDetail.frame=CGRectMake(60, 0, self.view.frame.size.width, 568);
    self.pushTitleLabel.text=@"车系论坛";
    [self.pushViewDetail addSubview:self.pushViewTitleView];
    [self.pushViewDetail addSubview:self.thridTabel];

    _tablecount=4;

    
    [self.thridTabel reloadData];
    
    
    self.BiggestView.hidden=NO;
    self.BiggestView.backgroundColor=[UIColor grayColor];
    self.BiggestView.alpha=0.8;
    [self.view bringSubviewToFront:self.pushViewDetail];
    self.firstTableView.userInteractionEnabled=NO;
    self.tabBarController.tabBar.hidden=YES;
    
    
    
    
    
    
    
    
    
    
}











#pragma mark======================地区论坛推出的页面
-(void)pushToCityForum
{
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationBeginsFromCurrentState:2];
    self.pushView.frame=CGRectMake(60, 0, self.view.frame.size.width, 568);
    
    
    self.pushTitleLabel.text=@"地区论坛";
    
    
    
    _tablecount=2;
    
    [self.thridTabel reloadData];
    self.BiggestView.hidden=NO;
    self.BiggestView.backgroundColor=[UIColor grayColor];
    self.BiggestView.alpha=0.8;
    [self.view bringSubviewToFront:self.pushView];
    self.firstTableView.userInteractionEnabled=NO;
    self.tabBarController.tabBar.hidden=YES;
    
    
    [UIView commitAnimations];

    
    
    
}


#pragma mark=====================主题论坛
-(void)pushToThameForum
{
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationBeginsFromCurrentState:2];
    
    self.pushView.frame=CGRectMake(60, 0, self.view.frame.size.width, 568);
    self.pushTitleLabel.text=@"主题论坛";
    _tablecount=3;
    
    
    [self.thridTabel reloadData];
    
    self.BiggestView.hidden=NO;
    self.BiggestView.backgroundColor=[UIColor grayColor];
    self.BiggestView.alpha=0.8;
    
    [self.view bringSubviewToFront:self.pushView];
    self.firstTableView.userInteractionEnabled=NO;
    self.tabBarController.tabBar.hidden=YES;
    
    
    [UIView commitAnimations];
    
    
    
    
}




#pragma mark------UITableViewDataSource,UITableViewDelegate

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if (tableView.tag==2001)
    {
        return _dataArray.count;
    }
    else if(tableView.tag==2002)
    {
        
        return 3;
    }
    else if(tableView.tag==2003)
    {
        if (_tablecount==0) {
            
        
        return _titleArray.count;
        }else if (_tablecount==1)
        {
            //取到对应段的数组
            NSArray *array=_CarNameArray[section];
            
            //返回小数组个数
            return array.count;
            
        
        }
        else if (_tablecount==2)
        {
            NSArray *array=_CityName[section];
            return array.count;
            
        }
        else if (_tablecount==3)
        {
            return _ThemeArray.count;
            
        }else if (_tablecount==4)
        {
            return _ABTarray.count;
        }
        else
        {
            
            return 1;
        }
    }
    else{
        return 1;
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    //精选日报
    if (tableView.tag==2001)
    {
        return 1;
        
        
    }
    //常用论坛
    else if(tableView.tag==2002)
    {
    
    return 1;
    }
    //推出界面
    else if(tableView.tag==2003)
    {
        if (_tablecount==0)
        {
            
        
            return 1;
        }
        else if (_tablecount==1)
        {
            
            return _CheXiTitleArray.count;
        }
        else if (_tablecount==2)
        {
            return _CityTitleCharArray.count;
            
            
        }
        else if (_tablecount==3)
        {
            
            return 1;
            
        }
        else if (_tablecount==4)
        {
            
            return 1;
            
        }
        else
        {
            return 1;
        }
    }
    else
    {
        
        return 1;
    }
}

-(UITableViewCell*)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    //精选日报
    if (tableView.tag==2001)
    {
        
    
    
    CustomCell*cell=[tableView dequeueReusableCellWithIdentifier:@"CustomCell"];
        ForumModel*model=_dataArray[indexPath.row];
        [cell.imgView setImageWithURL:[NSURL URLWithString:model.imgurl]];
        
        cell.contextLabel.text=model.titleLabel;
        cell.buyAddressAndCountLabel.text=model.typeLabel;
        cell.answerCountLabel.text= [NSString stringWithFormat:@"%@回",model.answer];
   
    return cell;
    }
    else if(tableView.tag==2002)
    {
        
        SecondCustomCell*cell=[tableView dequeueReusableCellWithIdentifier:@"SecondCustomCell"];
        
        cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;
        
        if (indexPath.row==0)
        {
            
        
            cell.setimgView.image=[UIImage imageNamed:@"forum_icon_auto.png"];
            cell.setTitleLabel.text=@"车系论坛";
            cell.setContextLabel.text=@"为你的爱车找队伍";
            
        }
        else if (indexPath.row==1)
        {
            
            cell.setimgView.image=[UIImage imageNamed:@"forum_icon_location.png"];
            cell.setTitleLabel.text=@"地区论坛";
            cell.setContextLabel.text=@"老乡见老乡,两眼泪汪汪";
            
        }
        else
        {
            cell.setimgView.image=[UIImage imageNamed:@"forum_icon_theme.png"];
            cell.setTitleLabel.text=@"主题论坛";
            cell.setContextLabel.text=@"兴趣爱好的聚集地";
            
            
        }
        
            
            
        return cell;
    }
    else
    {
        
       
            
        
        ThirdCustomCell *cell=[tableView dequeueReusableCellWithIdentifier:@"ThirdCustomCell"];
        cell.tag=700+indexPath.row;
        
        
        if (_tablecount==0)
        {
            
        
            cell.imageView.image=nil;
       cell.textLabel.text=_titleArray[indexPath.row];
     
      
        
        
        
            
            if (indexPath.row==0)
            {

                cell.accessoryType=UITableViewCellAccessoryCheckmark;
            }
            else
            {
                
                cell.accessoryType=UITableViewCellAccessoryNone;
            }
           
        
    
    
            if(indexPath.row==_cellcount)
            {
                cell.accessoryType=UITableViewCellAccessoryCheckmark;

            }
            else
            {
                cell.accessoryType=UITableViewCellAccessoryNone;
                
            }
                
        

        return cell;
        }
        
        else if(_tablecount==1)
        {
        
            cell.accessoryType=UITableViewCellStyleDefault;
            
//
//            NSString *path=[[NSBundle mainBundle] pathForResource:@"AHCache.plist" ofType:nil];
//            NSDictionary *dict=[NSDictionary dictionaryWithContentsOfFile:path];
//            
//            NSDictionary *result=dict[@"result"];
//            NSArray *brandlist=result[@"brandlist"];
//        
//            
//            for (NSDictionary *dic in brandlist) {
//                
//            }
            

            NSArray *arry=_CarNameArray[indexPath.section];
            //车系论坛推出的tableviewcell
            
            cell.textLabel.text=arry[indexPath.row];
            cell.imageView.image=[UIImage imageNamed:arry[indexPath.row]];
            
//            [self.thridTabel scrollToRowAtIndexPath:0 atScrollPosition:UITableViewScrollPositionNone animated:NO];
            
         
            
            return cell;
            
            
        }
        else if (_tablecount==2)
        {
            cell.accessoryType=UITableViewCellStyleDefault;
            
            cell.imageView.image=Nil;
            
            NSArray *array=_CityName[indexPath.section];
            
            cell.textLabel.text=array[indexPath.row];
            
            
            return cell;
            
        }
        else if (_tablecount==3)
        {
            cell.accessoryType=UITableViewCellStyleDefault;
            
            cell.imageView.image=nil;
     
            
            cell.textLabel.text=_ThemeArray[indexPath.row];
            return cell;
            
            
        }else if(_tablecount==4)
        {
            
            cell.accessoryType=UITableViewCellStyleDefault;
            cell.imageView.image=nil;
            cell.textLabel.text=_ABTarray[indexPath.row];
            return cell;
        }
        else
        {
            return cell;
        }
        
        
        
    }
    
}



-(NSString *)tableView:(UITableView *)tableView titleForHeaderInSection:(NSInteger)section
{
    
    
    if (tableView.tag==2001)
    {
        return nil;
    }
    else if (tableView.tag==2002)
    {
        
        return nil;
        
    }
    else if(tableView.tag==2003)
    {
        if (_tablecount==0)
        {
            return nil;
        }
        else if (_tablecount==1)
        {
            
            switch (section) {
                case 0:
                    return _CheXiTitleArray[0];
                    break;
                case 1:
                    return _CheXiTitleArray[1];
                    break;
                case 2:
                    return _CheXiTitleArray[2];
                    break;
                case 3:
                    return _CheXiTitleArray[3];
                    break;
                case 4:
                    return _CheXiTitleArray[4];
                    break;
                case 5:
                    return _CheXiTitleArray[5];
                    break;
                case 6:
                    return _CheXiTitleArray[6];
                    break;
                case 7:
                    return _CheXiTitleArray[7];
                    break;
                case 8:
                    return _CheXiTitleArray[8];
                    break;
                case 9:
                    return _CheXiTitleArray[9];
                    break;
                case 10:
                    return _CheXiTitleArray[10];
                    
                    break;
                case 11:
                    return _CheXiTitleArray[11];
                    break;
                case 12:
                    return _CheXiTitleArray[12];
                    break;
                case 13:
                    return _CheXiTitleArray[13];
                    break;
                case 14:
                    return _CheXiTitleArray[14];
                    break;
                case 15:
                    return _CheXiTitleArray[15];
                    break;
                case 16:
                    return _CheXiTitleArray[16];
                    break;
                case 17:
                    return _CheXiTitleArray[17];
                    break;
                case 18:
                    return _CheXiTitleArray[18];
                    break;
                case 19:
                    return _CheXiTitleArray[19];
                    break;
                case 20:
                    return _CheXiTitleArray[20];
                    break;
                case 21:
                    return _CheXiTitleArray[21];
                    break;
                case 22:
                    return _CheXiTitleArray[22];
                    break;
                case 23:
                    return _CheXiTitleArray[23];
                    break;
                    
                    
                    
                default:
                    break;
            }
            
            return nil;

            
           
        }
        else if(_tablecount==2)
        {
            
            switch (section) {
                case 0:
                    return _CityTitleCharArray[0];
                    break;
                    
                case 1:
                    return _CityTitleCharArray[1];
                    break;
                case 2:
                    return _CityTitleCharArray[2];
                    break;
                case 3:
                    return _CityTitleCharArray[3];
                    break;
                case 4:
                    return _CityTitleCharArray[4];
                    break;
                case 5:
                    return _CityTitleCharArray[5];
                    break;
                case 6:
                    return _CityTitleCharArray[6];
                    break;
                case 7:
                    return _CityTitleCharArray[7];
                    break;
                case 8:
                    return _CityTitleCharArray[8];
                    break;
                case 9:
                    return _CityTitleCharArray[9];
                    break;
                case 10:
                    return _CityTitleCharArray[10];
                    break;
                case 11:
                    return _CityTitleCharArray[11];
                    break;
                case 12:
                    return _CityTitleCharArray[12];
                    break;
                case 13:
                    return _CityTitleCharArray[13];
                    break;
                case 14:
                    return _CityTitleCharArray[14];
                    break;
       
                    
                default:
                    break;
            }
            return nil;
            
        }
        else if (_tablecount==3)
        {
            return nil;
            
        }
        else if(_tablecount==4)
        {
            
            
            return nil;
        }
        else
        {
            
            return nil;
        }
        
        
    }
    else
    {
        return nil;
        
    }
    
}

-(NSArray *)sectionIndexTitlesForTableView:(UITableView *)tableView
{
    
    if (tableView.tag==2001)
    {
        return nil;
    }
    else if (tableView.tag==2002)
    {
        return nil;
        
    }
    else if (tableView.tag==2003)
    {

        if (_tablecount==0)
        {
            return nil;
        }
        else if (_tablecount==1)
        {
            
        
        
        return _CheXiTitleArray;
        }
        else if(_tablecount==2)
        {
            return _CityTitleCharArray;
            
        }
        else if (_tablecount==3)
        {
            
            return nil;
        }
        else if(_tablecount==4)
        {
            
            return nil;
        }
        else
        {
            
            return nil;
        }
    }
    else
    {
        
        return nil;
    }
}




//选中tableviewcell的每一行所触发的事件

-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView.tag==2001)
    {
        NSLog(@"跳转");
        

        ForumModel *model=_dataArray[indexPath.row];
        tableView.userInteractionEnabled=YES;
        JinXViewController*dvc=[self.storyboard instantiateViewControllerWithIdentifier:@"JinXViewController"];
        dvc.topid=[model.topicid intValue];
        [self presentViewController:dvc animated:YES completion:nil];
        
        
        
    }
    else if (tableView.tag==2002)
    {
        if (indexPath.row==0)
        {
            
        
        [self pushToCheXiForum];
        
        }
        else if (indexPath.row==1)
        {
            NSLog(@"第二行被点击");
            
            [self pushToCityForum];
            
            
            
        }
        else if (indexPath.row==2)
        {
            NSLog(@"第%d行被点击",(int)indexPath.row+1);
            
            
            [self pushToThameForum];
            
            
        }else
        {
            
            NSLog(@"hahahhahahaha");
        }
        
        
        
    }
    else if(tableView.tag==2003)
    {
        
        
        if (_tablecount==0)
        {
            
        
        
        ThirdCustomCell *cell=(ThirdCustomCell*)[tableView viewWithTag:indexPath.row+700];
        
        cell.accessoryType=UITableViewCellAccessoryCheckmark;
        
        UIButton *bit=(UIButton *)[self.smallScrollView viewWithTag:indexPath.row+100];
        [self click:bit];
        [UIView beginAnimations:nil context:nil];
        [UIView setAnimationDuration:2.0];
        self.smallScrollView.contentOffset=CGPointMake(bit.frame.origin.x,0);
        
        [self closePushView];
        [UIView commitAnimations];
        
        }
        
        else if (_tablecount==1)
        {
            
            //车系论坛
            
            if (indexPath.section==0) {
                if (indexPath.row==0) {
                    
                    self.backButton.hidden=NO;
                    [self pushToCheXiEveryOne];
                }
            }
       
            

        }else if(_tablecount==4)
        {
            
            
            FrumDetailViewController *FDvc=[self.storyboard instantiateViewControllerWithIdentifier:@"FrumDetailViewController"];
            
            [self presentViewController:FDvc animated:YES completion:nil];
            
            
        }
        
        
        

    }
    else
    
    {
        
        
        
    }
    
    
    
    
}





-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if (tableView.tag==2001) {
        return 80;
    }else{
        return 60;}
}








#pragma mark-------推出侧面窗口
- (IBAction)pushRightViewOut:(id)sender {
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationBeginsFromCurrentState:1.0];
    
    
    self.pushView.frame=CGRectMake(60, 0, self.view.frame.size.width, 568);
    self.BiggestView.hidden=NO;
    self.BiggestView.backgroundColor=[UIColor grayColor];
    self.BiggestView.alpha=0.8;
    [self.view bringSubviewToFront:_pushView];
    self.firstTableView.userInteractionEnabled=NO;
    self.tabBarController.tabBar.hidden=YES;
    
    _tablecount=0;
    [self.thridTabel reloadData];
    [UIView commitAnimations];
    
    
    
    
    
}
#pragma mark-------搜索功能
- (IBAction)searchResult:(id)sender {
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
